
package util;

import java.util.LinkedList;

/**
 *
 * @author Jah Emanuel
 */
public class Movement {
    private LinkedList<Position> positions;
    private boolean isJump = false;
    
    public Movement(){
        positions=new LinkedList<Position>();
    }
    
    public void addPosition(Position pos){
        positions.add(pos); 
    }
    public LinkedList<Position> getListOfPositions(){
        return positions;
    }
    public boolean hasNoPositions(){
        return positions.isEmpty();
    }
    public Movement(Position iniPos, Position finalPos){
        positions=new LinkedList<Position>();
        positions.add(iniPos);
        positions.add(finalPos);
    }
    private Movement(LinkedList<Position> positions, boolean isJump){
        this.positions=positions;
        this.isJump=isJump;
    }

    public boolean isJump() {
        return isJump;
    }

    public void setIsJump(boolean isJump) {
        this.isJump = isJump;
    }
    
    public boolean isPartOfJump(Movement jump){
        if(!this.isJump || !jump.isJump)
            return false;
        for(int i=0;i<this.positions.size();i++){
            if(i>=jump.positions.size()){
                return false;
            }
            if(!this.positions.get(i).equals(jump.positions.get(i))){
                return false;
            }
        }
        return true;
    }
    
    @Override
    public String toString(){
        
        String res="";
        if(isJump())
            res="Es salto: ";
        for (Position position : positions) {
            res = res+" " + position.toString();
        }
        return res;
    }
    
    @Override
    public Movement clone(){
        LinkedList<Position> newPos=new LinkedList<Position>();
        for(Position pos:positions)
            newPos.add(pos);
        return new Movement(newPos, isJump);
    }
    
    @Override
    public boolean equals(Object obj){
        if(!(obj instanceof Movement)){
            return false;
        }
        Movement other=(Movement)obj;
        boolean equals;
        equals=!(this.isJump^other.isJump);
        if(this.positions.size()!=other.positions.size())
            return false;
        for (int i=0;i<this.positions.size();i++){
            if(!this.positions.get(i).equals(other.positions.get(i)))
                return false;
        }
        return equals;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 37 * hash + (this.positions != null ? this.positions.hashCode() : 0);
        hash = 37 * hash + (this.isJump ? 1 : 0);
        return hash;
    }
}